package com.sls.game.parser;

import java.util.Iterator;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.sls.game.pojo.yunen.YunEnRespInfo;

public class ParseYunRespInfo {

	private static Logger log = Logger.getLogger(ParseYunRespInfo.class);

	@SuppressWarnings("unchecked")
	public static YunEnRespInfo getInfoOfRecharge(String xml) {
		YunEnRespInfo respInfo = new YunEnRespInfo();
		Document document = null;
		Element root = null;
		// 读取XML文件,获得document对象
		try {
			document = DocumentHelper.parseText(xml);
			root = document.getRootElement();
			Iterator<Element> it = root.elementIterator();
			while (it.hasNext()) {
				Element secondEle = it.next();
				String tagName = secondEle.getName();
				if ("order_id".equals(tagName)) {
					respInfo.setYunenOrderId(secondEle.getTextTrim());
				} else if ("outer_order_id".equals(tagName)) {
					respInfo.setOrderId(secondEle.getTextTrim());
				} else if ("order_status".equals(tagName)) {
					respInfo.setOrderStatus(secondEle.getTextTrim());
				} else if ("order_snap".equals(tagName)) {
					respInfo.setYunenOrderSnap(secondEle.getTextTrim());
				} else if ("order_success_time".equals(tagName)) {
					respInfo.setOrderSuccessTime(secondEle.getTextTrim());
				} else if ("failed_code".equals(tagName)) {
					respInfo.setFailedCode(secondEle.getTextTrim());
				} else if ("failed_text".equals(tagName)) {
					respInfo.setFailedReason(secondEle.getTextTrim());
				} else if ("failed_reason".equals(tagName)) {
					respInfo.setFailedReason(secondEle.getTextTrim());
				} else if ("success_num".equals(tagName)) {
					respInfo.setSuccessNum(secondEle.getTextTrim());
				}
			}
		} catch (DocumentException e) {
			log.error("解析云恩充值接口返回结果异常", e);
		}
		return respInfo;
	}

}
